<template>
  <view class="evaluate">
    <view class="top" v-if="isTitle">
      <view class="title"> 评价 </view>
      <view class="more" @tap="emit('more')">
				<view class="text"> 查看更多 </view>
				<image src="/static/icon/order/right.png" class="right" />
			</view>
    </view>
    <view class="tab-bar" v-if="isTab">
      <view class="tab-item" :class="type==0?'a-item':''" @tap="tapType(0)"> 全部 </view>
      <view class="tab-item" :class="type==1?'a-item':''" @tap="tapType(1)"> 最新 </view>
      <view class="tab-item" :class="type==2?'a-item':''" @tap="tapType(2)"> 好评 </view>
      <view class="tab-item" :class="type==3?'a-item':''" @tap="tapType(3)"> 差评 </view>
      <view class="tab-item" :class="type==4?'a-item':''" @tap="tapType(4)"> 有图 </view>
    </view>
    <!-- 评价详情 -->
    <view class="eva-details" v-for="item in evaList" :key="item" v-if="evaList.length">
      <view class="eva-top">
        <view class="user-info">
          <image :src="item.avatar" class="avatar" />
          <view class="user-name">
            <view class="name"> {{item.member_name}} </view>
            <view class="time"> {{item.create_time}} </view>
          </view>
        </view>
        <view class="star-box">
					<view class="star" :class="item.star>=xx?'a-star':''" v-for="xx in 5" :key="'xx'+xx"> </view>
        </view>
      </view>
      <view class="eva-info">
        <view class="text"> {{item.detail}} </view>
        <view class="img-box">
          <image :src="img" v-for="img in item.img" :key="img" class="i-img"/>
        </view>
        <view class="reply" v-if="item.reply">
          <view> {{item.reply}} </view>
        </view>
      </view>
    </view>
		<Empty txt="该商品暂时没有评价~" v-else/>
  </view>
</template>

<script setup>
	import { ref } from 'vue';
	import Empty from '@/components/Empty.vue';
	const emit = defineEmits(['tapType', 'more'])
  const props = defineProps({
    isTab: {
      type: Boolean,
      default: true
    },
    isTitle: {
      type: Boolean,
      default: true
    },
		evaList: {
			type: Array,
		}
  })
	const type = ref(0)
	const tapType = (e) => {
		if(e == type.value) return
		type.value = e
		emit('tapType', e)
	}
</script>

<style lang="scss" scoped>
  .evaluate {
    background-color: #fff;
    padding: 0px 16px 10px;
    box-sizing: border-box;
    .top {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .title {
        height: 19px;
        font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
        font-weight: 400;
        font-size: 16px;
        color: #333333;
        line-height: 19px;
      }
      .more {
				display: flex;
				align-items: center;
        .text {
					color: #999999;
					font-size: 12px;
					font-weight: 400;
					line-height: 14px;
				}
				.right {
					width: 16px;
					height: 16px;
					margin-left: 1px;
				}
      }
    }
    .tab-bar {
      display: flex;
      margin-top: 10px;
      margin-bottom: 6px;
      .tab-item {
        width: 44px;
        height: 22px;
        color: #666666;
        background: #F0F0F0;
        font-size: 12px;
        border-radius: 4px;
        margin-right: 4px;
        text-align: center;
        line-height: 22px;
        &.a-item {
          color: #FF3B1E;
          background: #FFEFF1;
        }
      }
    }
    // 评价详情
    .eva-details {
      margin-top: 10px;
      padding-bottom: 10px;
      border-bottom: 1px solid #E6E6E6;
      .eva-top {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .user-info {
          display: flex;
          .avatar {
            width: 32px;
            height: 32px;
            margin-right: 10px;
						border-radius: 50%;
          }
          .name {
            font-weight: 500;
            font-size: 14px;
            color: #666666;
            line-height: 17px;
          }
          .time {
            font-weight: 400;
            font-size: 12px;
            color: #999999;
            line-height: 16px;
          }
        }
        .star-box {
					display: flex;
					align-items: center;
					.star {
						width: 12px;
						height: 12px;
						margin-right: 4px;
						background: url('/static/icon/rider/xx.png') no-repeat center center;
						background-size: 100% 100%;
						&:nth-last-of-type(1) {
							margin-right: 0;
						}
						&.a-star {
							background: url('/static/icon/rider/a-xx.png') no-repeat center center;
							background-size: 100% 100%;
						}
					}
        }
      }
      .eva-info {
        margin-top: 10px;
        .text {
          font-weight: 400;
          font-size: 14px;
          color: #666666;
          line-height: 19px;
        }
        .img-box {
          margin: 10px 0;
          display: grid;
          grid-template-columns: repeat(3, 1fr); /* 创建5列 */
          gap: 9px; /* 如果需要间距，可以设置为非零值 */
          box-sizing: border-box; /* 确保内边距不会增加容器大小 */
          .i-img {
            width: 109px;
            height: 109px;
          }
        }
        .reply {
          padding: 6px 10px;
          background: #F4F4F4;
          border-radius: 5px 5px 5px 5px;
          view {
            font-weight: 400;
            font-size: 14px;
            color: #999999;
            line-height: 19px;
          }
        }
      }
    }
  }
</style>